package br.com.lavitstudio.game;

import java.util.Random;

public class Spawner implements Runnable{
	public boolean isRunning = false;
	
	public Spawner() {
		isRunning = true;
		new Thread(this).start();
	}
	
	public void spawnMob(Mob mob) {
		Component.mob.add(mob);
	}

	public void spawnMobAnimal(Mob mob) {
		Component.mobAnimal.add(mob);
	}

	public void run() {
		while(isRunning){
			// Adiciona Mobs Animals e remove monstros
			if(Component.mobAnimal.toArray().length < Tile.maxMobsAnimals && Sky.time == 0) {
				spawnMobAnimal(new mob_Animal(new Random().nextInt(2)+1));
			}
			
			// Adiciona Mobs Noite
			if(Component.mob.toArray().length < Tile.maxMobs && Sky.time == 1) {
				spawnMob(new mob_Orc(new Random().nextInt(3)+1));
			}
			
			
			try {
				Thread.sleep(new Random().nextInt(8000) + 5000);
			} catch(Exception e) { }
		}
	}
}
